var Page = function(){
    this.init();
};
Page.prototype = {
    params: {
        passport: '',
        boxOrderNumber:''
    },
    init: function(){
        this.initParams();
        this.initEvent();
    },
    initParams: function(){
        this.params.passport = Pub.getCookie('_PASSPORT');
        this.params.boxOrderNumber = Pub.getSession('boxOrderNumber');
    },
    getData: function(){
        var _this = this;
        var paramsObj = {
            passport: _this.params.passport,
            boxOrderNumber:_this.params.boxOrderNumber
        };
        console.log(paramsObj);
        Api.packinglistdetails(paramsObj, function(data){
            console.log(data);
            var data=data.data;
            $('#orderNum').text(data.boxOrderNumber);
            $('#boxOrderNumber').text(data.boxOrderNumber);
            $('#operator').text(data.operator);
            $('#gmtCreate').text(data.gmtCreate);
            //$('#doorTime').text(data.doorTime[0]+'~'+data.doorTime[1]);
            $('#carNumber').text(data.carNumber);
            $('#boxContent').text(data.boxContent);
            $('#totalWeight').text(data.totalWeight);
            $('#volume').text(data.volume);

            $('#send_name').text(data.sendStationId.branchName);
            $('#send_mobile').text(data.sendStationId.mobile);
            $('#send_address').text(data.sendStationId.address);

            $('#recipient_name').text(data.receiveStationId.branchName);
            $('#recipient_mobile').text(data.receiveStationId.mobile);
            $('#recipient_address').text(data.receiveStationId.address);

            $('#courierRealName').text(data.operator);
            $('#courierMobile').text(data.sendStationId.mobile);
            $('#pickCode').text(data.pickCode);

            $('#courierType').text(data.expressName);


            switch (data.state) {

                case 10:
                    $('.state').text('装箱');
                    break;
                case 15:
                    $('.state').text('拆箱');
                    break;
                case 20:
                    $('.state').text('待中转');
                    break;

            }

        });
    },
    getOperation:function(){
        var _this = this;
        var Params = {
            passport: _this.params.passport,
            boxOrderNumber:_this.params.boxOrderNumber
        };
        console.log(Params);
        Api.packingoperationlist(Params, function(data) {
            console.log(data);
            _this.getDataList(data.list);
        })
    },
    getDataList:function(data){
        var _this = this;
        if (data && data.length > 0) {
            var html = '',
                i = 0,
                len = data.length;
            for (i; i < len; i++) {
                html += '<tr>' +
                        '<td class="text-c">' + data[i].operator + '</td>' +
                        '<td class="text-c">' + data[i].mobile + '</td>'+
                        '<td class="text-c">' + data[i].gmtCreate + '</td>';
                switch (data[i].state) {
                    case 10:
                        html += '<td class="text-c">装箱</td>';
                        break;
                    case 15:
                        html += '<td class="text-c">拆箱</td>';
                        break;
                    case 20:
                        html += '<td class="text-c">待中转</td>';
                        break;
                    case 30:
                        html += '<td class="text-c">中转中</td>';
                        break;

                }
                html += '<td class="text-c">' + data[i].remark + '</td>' +
                    '</tr>';
            }
            $('#opList').html(html);

        } else {
            var html = '<tr>' +
                '<td class="text-c c-666" colspan="5" >暂无数据</td>' +
                '</tr>';
            $('#opList').html(html);

        }
    },
    addremark:function(){
        var _this = this;
        var remark=$('#remarkVal').val();
        var Params = {
            passport: _this.params.passport,
            boxOrderNumber:_this.params.boxOrderNumber,
            remark:remark,
            isPick:2
        };
        console.log(Params);
        Api.packingaddremark(Params, function(data) {
            _this.getData();
            _this.getOperation();
            layui.use('layer', function(){
                layer.msg('备注成功', {icon: 6});
            });
            $('#modal_remark').modal('hide');
        })
    },
    otherEvent:function(){
        var _this = this;
        $('.goods-checkbox input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        })
        $('#remark_order').click(function(event) {
            $('#modal_remark').modal('show');
            $('#remarkVal').val('');
        });
        $('#remarkYes').click(function(event) {
            _this.addremark();
        });
    },
    initEvent: function(){
        var _this = this;
        _this.getData();
        _this.otherEvent();
        _this.getOperation();

    }
};
var page = new Page();